﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Collections.Generic;
using System.Text;

using ProyectoFinal.Controles;


public partial class frmPlan : System.Web.UI.Page
{
    String strcon;
    conCurso ctrCurso;
    conPlanCurricular ctrPlan;

    protected void Page_Load(object sender, EventArgs e)
    {
        strcon = ConfigurationManager.ConnectionStrings["localConnectionString"].ConnectionString;

        if (!this.IsPostBack)
        {
            ctrPlan = new conPlanCurricular(strcon);

            DataView dv = new DataView(ctrPlan.ObtenerDatosFacultad());


            DropDownList1.DataSource = dv;
            DropDownList1.DataTextField = "nombre";
            DropDownList1.DataValueField = "codigo";
            DropDownList1.DataBind();

        }

        lblmsg.Text = "";
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {

    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        ctrCurso = new conCurso(strcon);

        DataTable dt = ctrCurso.ObtenerCursosXFacultad(Convert.ToInt32(DropDownList1.SelectedValue));

        if (dt.Rows.Count == 0)
            lblmsg.Text = "No se encontro resultados.";
        else
            lblmsg.Text = dt.Rows.Count + " resultados encontrados.";
        

        DataView dv = new DataView(dt);

        ListBox1.DataSource = dv;
        ListBox1.DataTextField = "nombre";
        ListBox1.DataValueField = "codigo";
        ListBox1.DataBind();                                                                                                                                                                
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (ListBox1.SelectedValue == "")
            return;

        ListBox1.SelectionMode = ListSelectionMode.Multiple;

        ListItem item = ListBox1.SelectedItem;
        ListBox2.Items.Add(item);

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        if (ListBox2.SelectedValue == "")
            return;

        ListItem item = ListBox2.SelectedItem;

        ListBox2.Items.Remove(item);

    }

    protected void Button4_Click(object sender, EventArgs e)
    {
        ctrPlan = new conPlanCurricular(strcon);

        List<int> cursos = new List<int>();

        foreach (ListItem i in ListBox2.Items)
        {
            cursos.Add(Convert.ToInt32(i.Value));
        }

        //control.grabarDatosPC(TextBox1.Text, Convert.ToInt32(DropDownList1.SelectedValue),cursos);
        
        Label4.Text = "Datos fueron grabados";
    }
    protected void ListBox2_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        Response.Redirect("frmMain.aspx");
    }
}
